home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
dlgds411.zip
/
CPPSRC2.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-12
|
19KB
|
746 lines
/*Substitutions and fills in file, cppskel.dat
Area Fills
@ZZ0 Form the dialog in constructor
@ZZ1 Defined Control Names in Object Def.
@ZZ2 Data struct def
@ZZ3 Variable names in 'read'
@ZZ4 Variable names in 'write'
@ZZ5 Ancestor constructor call
@ZZ6 Uses_ stuff
@ZZ7 include of tcolortx.h, tinplong.h
@ZZ8 Links
Substitutions
@XX1 Dialog's Symbol (as TMyDialog)
@XX2 Dialog's ancestor (usually TDialog)
@XX3 Dialog's registration TStreamRec (as RMyDialog)
@XX4 Filename (upper case)
@XX5 Filename (lower case)
*/
#define Uses_TStringCollection
#include <tv.h>
#include <stdlib.h>
#include <dos.h>
#include <dir.h>
#include <fcntl.h>
#include <string.h>
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include "readscpt.h"
ofstream outf;
ifstream data;
#define BIG 300
char s[BIG], upperName[MAXFILE], lowerName[MAXFILE];
Boolean needcontrol1 = False;
char* quoted(const char* s)
//if the first char of s is '@', assumes a variable wanted and strips the '@'
//else returns a double quoted string or 0 for empty string
{
static char q[300];
if (s[0] == '@')
{strcpy(q, &s[1]);
return q;
}
strcpy(q, "\""); //the first quote in place
if (*s == '\0' || !s) return "0";
strcat(q, s);
short l = strlen(q);
q[l] = '\"';
q[l+1] = '\0';
return q;
}
void aField(ViewObj *P, char* fieldtype)
{
outf << " " << fieldtype << " " << P->FieldName << "; //" << P->Obj <<endl;
}
void aVar(ViewObj *P)
{
if (strcmp(P->VarName, "control") != 0)
outf << " " << P->Obj << " *" << P->VarName << ";\n";
}
//the following extend the ViewObj struct's to also write the code
struct DialogWriteObj : DialogObj {
virtual void writeCode();
};
struct ButtonWriteObj : ButtonObj {
virtual void writeCode();
virtual void writeVars() {aVar(this);};
};
struct InputLongWriteObj : InputLongObj {
virtual void writeCode();
virtual void writeFields() {aField(this, "long");} ;
virtual void writeVars() {aVar(this);};
};
struct LabelWriteObj : LabelObj {
virtual void writeCode();
};
struct HistoryWriteObj : HistoryObj {
virtual void writeCode();
};
struct InputLineWriteObj : InputLineObj {
virtual void writeCode();
virtual void writeFields();
virtual void writeVars() {aVar(this);};
};
struct ClusterWriteObj : ClusterObj {
virtual void writeCode();
virtual void writeFields() {aField(this, "ushort");} ;
virtual void writeVars() {aVar(this);};
};
struct ListBoxWriteObj : ListBoxObj {
virtual void writeCode();
virtual void writeFields() {aField(this, "TListBoxRec");} ;
virtual void writeVars() {aVar(this);};
};
struct ScrollBarWriteObj : ScrollBarObj {
virtual void writeCode();
virtual void writeVars();
};
struct MemoWriteObj : MemoObj {
virtual void writeCode();
virtual void writeFields();
virtual void writeVars() {aVar(this);};
};
struct StaticTextWriteObj : StaticTextObj {
virtual void writeCode();
virtual void writeVars() {aVar(this);};
};
struct ColoredTextWriteObj : ColoredTextObj {
virtual void writeCode();
virtual void writeVars() {aVar(this);};
};
//now that we know the final extensions of ViewObj, we can write the
//getKind function
ViewObj *getKind(recType Kind)
{ ViewObj *P;
switch (Kind) {
case Dlg : P = new DialogWriteObj(); break;
case Button : P = new ButtonWriteObj(); break;
case InputL : P = new InputLineWriteObj(); break;
case Labl : P = new LabelWriteObj(); break;
case Histry : P = new HistoryWriteObj(); break;
case ILong : P = new InputLongWriteObj(); break;
case CheckB: P = new ClusterWriteObj(); break;
case RadioB: P = new ClusterWriteObj(); break;
case MultiCB: P = new MultiCheckBoxObj(); break;
case ListB: P = new ListBoxWriteObj(); break;
case ScrollB : P = new ScrollBarWriteObj(); break;
case Memo: P = new MemoWriteObj(); break;
case SText: P = new StaticTextWriteObj(); break;
case CText : P = new ColoredTextWriteObj(); break;
default : P = 0; break;
}
return P;
}
char * getWinFlagWords(ushort w, char *s)
//given the set bits return names in 'or' form
{
static char *flagArray[4] = {
"wfMove", "wfGrow", "wfClose", "wfZoom"};
s[0] = '\0';
for (int i = 0; i <= 3; i++) {
if ((w & 1) == 1 && flagArray[i][0] != '\0')
strcat(strcat(s, flagArray[i]), " | ");
w >>= 1;
}
int l = strlen(s);
if (l > 4)
s[l-3] = '\0'; //remove last " | "
return s;
}
char * getEventWords(ushort w, char *s)
//given the set bits return names in 'or' form
{
static char *flagArray[16] = {
"evMouseDown", "evMouseUp", "evMouseMove", "evMouseAuto",
"evKeyDown", "0x20", "0x40", "0x80", "evCommand", "evBroadcast",
"0x400", "0x800", "0x1000", "0x2000", "0x4000", "0x8000"};
s[0] = '\0';
for (int i = 0; i <= 15; i++) {
if ((w & 1) == 1 && flagArray[i][0] != '\0')
strcat(strcat(s, flagArray[i]), " | ");
w >>= 1;
}
int l = strlen(s);
if (l > 4)
s[l-3] = '\0'; //remove last " | "
return s;
}
char * getOptionWords(ushort w, char *s)
//given the set bits return names in 'or' form
{
static char *flagArray[16] = {
"ofSelectable", "ofTopSelect", "ofFirstClick", "ofFramed",
"ofPreProcess", "ofPostProcess", "ofBuffered", "ofTileable",
"ofCenterX", "ofCenterY", "ofValidate", "0x800", "0x1000",
"0x2000", "0x4000", "ofShoehorn"};
s[0] = '\0';
for (int i = 0; i <= 15; i++) {
if ((w & 1) == 1 && flagArray[i][0] != '\0')
strcat(strcat(s, flagArray[i]), " | ");
w >>= 1;
}
int l = strlen(s);
if (l > 4)
s[l-3] = '\0'; //remove last " | "
return s;
}
short bitCount(ushort w) //numbers of set bits in the word
{
short count = 0;
for (int i = 0; i <= 15; i++) {
if ((w & 1) == 1)
count++;
w >>= 1;
}
return count;
}
void doBitOutput(const char* var, const char* pre, ushort actual,
ushort defaul, char* (func)(ushort w, char* s))
//output something like "foo->options |= ofSelectable or ofFramed;"
//and/or "foo-> options &= ofTopSelect;"
//actual is the bits set and defaul are the default settings
//it's known that actual and defaul are not equal on entry
{
char s[100];
ushort NOTs, ORs, diff ;
diff = actual ^ defaul; //the bits that are different
if (bitCount(diff) > 5) { //this is too complex--output hex number
outf << " " << var << pre << " = 0x" << hex << actual << dec <<";\n";
return;
}
NOTs = diff & defaul; //the bits not in defaul
ORs = diff & actual; //the extra bits in actual
s[0] = '\0';
if (NOTs != 0) {
outf << " " << var <<pre;
if (bitCount(NOTs) == 1)
outf << " &= ~" << func(NOTs, s) << ";\n";
else
outf << " &= ~(" << func(NOTs, s) << ");\n";
}
s[0] = '\0';
if (ORs != 0)
outf << " " << var << pre << " |= " << func(ORs, s) << ";\n";
}
void doTRect(ViewObj *P)
{
outf << "(TRect(" << P->X1 << ", " << P->Y1 << ", "
<< P->X2 << ", " << P->Y2 << ")";
}
void insertControl(const char *Name)
{
outf << " insert(" << Name << ");\n\n";
}
void doOpEvent(ViewObj *P)
{if (P->DefEvMsk != P->EvMsk)
doBitOutput(P->VarName, "->eventMask", P->EvMsk, P->DefEvMsk, getEventWords);
if (P->DefOptns != P->Optns)
doBitOutput(P->VarName, "->options", P->Optns, P->DefOptns, getOptionWords);
}
void writeHelpCtx(char * VarName, char* H, ushort Ctx)
{
if (*H != '\0') {
if (strcmp(H, "hcNoContext")) {
outf << " " << VarName << "->helpCtx = " << H << ";\n";
}
}
else if (Ctx != 0) {
outf << " " << VarName << "->helpCtx = " << Ctx << ";\n";
}
}
void start(ViewObj *P)
{
outf << " " << P->VarName << " = new " << P->Obj;
doTRect(P);
}
void finish(ViewObj *P)
{
writeHelpCtx(P->VarName, P->HelpCtxSym, P->HCtx);
doOpEv